import java.util.Arrays;

/**
 * @program: leetcode283
 * @author: JCM
 * @create: 2022-11-18 21:41
 * @description: 移动零
 **/
public class leetCode283 {
    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        moveZeroes(nums);
        System.out.println(Arrays.toString(nums));
    }

    private static void moveZeroes(int[] nums) {
        for(int i = 0; i < nums.length-1; i++) {
            int tmp = nums[i];
            if(tmp == 0) {
                for(int j = i+1;j < nums.length; j++) {
                    if(nums[j] != 0) {
                        nums[i] = nums[j];
                        nums[j] = tmp;
                        break;
                    }
                }
            }
        }
    }
}
